<template>
	<view class="news_item" @click="navigator(item.id)" v-for="item in list" :key="item.id">
		<image :src="item.img_url"></image>
		<view class="right">
			<view class="tit">{{ item.title }}</view>
			<view class="info">
				<text>发表时间：{{ item.add_time | formatDate }}</text>
				<text>浏览：{{ item.click }}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: ['list'],
		filters: {
			formatDate(date) {
				const nDate = new Date(date);
				const year = nDate.getFullYear();
				const month = (nDate.getMonth() + 1).toString().padStart(2, '0');
				const day = nDate.getDate().toString().padStart(2, '0');
				return `${year}-${month}-${day}`;
			}
		},
		methods: {
			navigator(id) {
				this.$emit('itemClick', id);
			}
		}
	};
</script>